<template>
	<view class="addCar">
		<view class="form">
			<view class="card">
				<view class="list">
					<view class="title">行驶证主面</view>
					<view class="upload flex-center" @click="upload('run_face_url')">
						<image :src="run_face_url" mode="aspectFill" class="bg" v-if="run_face_url"></image>
						<block v-else>
							<image src="/static/drive_face.png" mode="aspectFill" class="bg"></image>
							<image src="/static/upload.png" mode="widthFix" class="cemare"></image>
						</block>
						
					</view>
				</view>
				<view class="list">
					<view class="title">行驶证副面</view>
					<view class="upload flex-center" @click="upload('run_back_url')">
						<image :src="run_back_url" mode="aspectFill" class="bg" v-if="run_back_url"></image>
						<block v-else>
							<image src="/static/drive_back.png" mode="aspectFill" class="bg"></image>
							<image src="/static/upload.png" mode="widthFix" class="cemare"></image>
						</block>
					</view>
				</view>
			</view>
			<button @click="submitForm">确定提交</button>
		</view>
		
		<view class="tip flex">
			点击提交认证即表示已阅读并同意小王出行
			<navigator url="" hover-class="none">《隐私条款》</navigator>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				run_face_url:'',
				run_back_url:'',
				isSubmit:true,
			};
		},
		onLoad() {
			
		},
		methods:{
			upload(type){
				this.$https.upload().then(res=>{
					console.log(res)
					this[type] = res;
				})
			},
			submitForm(){
				if(!this.isSubmit) return;
				if(!this.run_face_url){
					uni.showToast({
						title:'请上传行驶证主面',
						icon:'none'
					})
					return
				}
				if(!this.run_back_url){
					uni.showToast({
						title:'请上传行驶证副面',
						icon:'none'
					})
					return
				}
				this.isSubmit = false;
				this.$https.post('car_auth/save',{
					run_face_url:this.run_face_url,
					run_back_url:this.run_back_url,
				}).then(res=>{
					uni.showToast({
						title:'添加成功,等待审核...',
						icon:"none"
					})
					uni.navigateBack({
						delta:1
					})
				}).catch(err=>{
					this.isSubmit = true
				})
			}
		}
	}
</script>

<style lang="less">
	page{
		background: #f2f3f4;
	}
	@color: #4CD964;
	.addCar{
		padding: 24rpx;
		.form{
			.card{
				background: white;
				border-radius: 5rpx;
				padding: 15rpx 24rpx;
				.title{
					line-height: 2;
				}
				.upload{
					height: 350rpx;
					margin-bottom: 20rpx;
					position: relative;
					.bg{
						position: absolute;
						top: 0;
						left: 0;
						width: 100%;
						height: 100%;
					}
					.cemare{
						position: relative;
						z-index: 1;
						width: 100rpx;
						height: auto;
					}
				}
			}
			button{
				margin: 40rpx 0 30rpx;
				background: @color;
				color:white;
			}
		}
		
		.tip{
			font-size: 26rpx;
			color:#999;
			navigator{
				color:@color;
			}
		}
	}
</style>
